package com.ruoyi.project.distribute.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.distribute.domain.HosProvide;
import com.ruoyi.project.distribute.service.IHosProvideService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *  供应商控制层方法
 * @author anran
 */
@RestController
@RequestMapping("/distribute/provide")
public class HosProvideController extends BaseController
{
    @Autowired
    private IHosProvideService hosProvideService;

    /**
     * 查询供应商全部信息
     */
    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('distribute:provide:list')")
    public TableDataInfo list(HosProvide hosProvide)
    {
        startPage();
        List<HosProvide> list = hosProvideService.selectByHosProvide(hosProvide);
        return getDataTable(list);
    }

    /**
     * 新增供应商信息
     */
    @PreAuthorize("@ss.hasPermi('distribute:provide:add')")
    @Log(title = "供应商信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HosProvide hosProvide)
    {
        hosProvide.setCreateBy(SecurityUtils.getUsername());
        return toAjax(hosProvideService.insertHosProvide(hosProvide));
    }

    /**
     * 导出供应商信息列表
     */
    @PreAuthorize("@ss.hasPermi('distribute:company:export')")
    @Log(title = "供应商信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HosProvide hosProvide)
    {
        List<HosProvide> list = hosProvideService.selectByHosProvide(hosProvide);
        ExcelUtil<HosProvide> util = new ExcelUtil<>(HosProvide.class);
        return util.exportExcel(list, "供应商信息");
    }

    /**
     * 删除供应商信息
     */
    @PreAuthorize("@ss.hasAnyPermi('distribute:provide:remove')")
    @Log(title = "供应商信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{provideIds}")
    public AjaxResult remove(@PathVariable Long[] provideIds)
    {
        return toAjax(hosProvideService.deleteHosProvideByID(provideIds));
    }

    /**
     * 根据ID查询供应商信息
     */
    @PreAuthorize("@ss.hasPermi('distribute:provide:query')")
    @GetMapping(value = "/{provideId}")
    public AjaxResult getInfo(@PathVariable("provideId") Long provideId)
    {
        return AjaxResult.success(hosProvideService.selectHosProvideByProvideId(provideId));
    }

    /**
     * 修改供应商信息
     */
    @PreAuthorize("@ss.hasPermi('distribute:provide:edit')")
    @Log(title = "供应商信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HosProvide hosProvide)
    {
        hosProvide.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(hosProvideService.updateHosProvide(hosProvide));
    }
}
